<?php
        include('libs/image.class.php');

        $json = $_POST;
        $file = 'uploadFile'.$json['elemId'];
        $path = 'tmp/';
        $name = basename($_FILES[$file]['tmp_name']);

        $img = new Upload($_FILES[$file]);

        $img->file_max_size      = 4096000;
        $img->allowed            = array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
        $img->file_new_name_body = $name;
        $img->image_min_width    = 64;
        $img->image_min_height   = 64;
        $img->image_resize       = true;
        $img->image_x            = $json['elemWidth'];
        $img->image_y            = $json['elemHeight'];
        $img->image_ratio        = true;
        //$img->image_ratio_crop   = true;
        $img->Process($path);

        if ($img->processed) {
            $json['status']   = 1;
            $json['filename'] = 'http://'.$_SERVER['HTTP_HOST'].'/ebay_listing/tmp/'.$img->file_dst_name;
            $img->Clean();
        } else {
            $json['status']  = -1;
            $json['message'] = $img->error;
        }

        echo json_encode($json);
        exit();
?>